<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>P-dd A simple example using the TestDatasource</title>
</head>
<body>

<?php

ini_set( 'include_path', '../;.' );

require_once( 'include_package.php' );

include_package( 'Datasources' );
include_package( 'DatabaseModel' );
include_package( 'Renderers' );
include_package( 'Renderers.HtmlRenderer' );
include_package( 'Xml' );

// TODO: WIP - Temporary file

$sXml = '<databaseDefinition>
	<database>
	<tableList>
      <table name="STUDENT" id="STUDENT">
        <column id="STUDENT.COLLEGE_ID" name="COLLEGE_ID" datatype="NUMBER" ispartofprimarykey="true" ispartofforeignkey="true" />
        <column id="STUDENT.ID" name="ID" datatype="NUMBER" ispartofprimarykey="true" ispartofforeignkey="false" />
        <column id="STUDENT.FIRST_NAME" name="FIRST_NAME" datatype="VARCHAR2" ispartofprimarykey="false" ispartofforeignkey="false" />
        <column id="STUDENT.SURNAME" name="SURNAME" datatype="VARCHAR2" ispartofprimarykey="false" ispartofforeignkey="false" />
        <column id="STUDENT.KNOWN_AS" name="KNOWN_AS" datatype="VARCHAR2" ispartofprimarykey="false" ispartofforeignkey="false" />
        <column id="STUDENT.REGISTRATION_NO" name="REGISTRATION_NO" datatype="VARCHAR2" ispartofprimarykey="false" ispartofforeignkey="false" />
        <primaryKey name="STUDENT_PK" id="STUDENT_PK">
          <primaryKeyColumn columnid="STUDENT.COLLEGE_ID" sequence="0" />
          <primaryKeyColumn columnid="STUDENT.ID" sequence="1" />
        </primaryKey>
        <foreignKeyFromList>
          <foreignKey name="STUDENT_COLLEGE_FK" id="STUDENT_COLLEGE_FK" fromtable="STUDENT" totable="COLLEGE" mandatory="true">
            <foreignKeyColumn columnid="STUDENT.COLLEGE_ID" sequence="0" />
          </foreignKey>
        </foreignKeyFromList>
      </table>
      <table name="ACTIVITY" id="ACTIVITY">
        <column id="ACTIVITY.ID" name="ID" datatype="NUMBER" ispartofprimarykey="true" ispartofforeignkey="false" />
        <column id="ACTIVITY.NAME" name="NAME" datatype="VARCHAR2" ispartofprimarykey="false" ispartofforeignkey="false" />
        <column id="ACTIVITY.DESCRIPTION" name="DESCRIPTION" datatype="VARCHAR2" ispartofprimarykey="false" ispartofforeignkey="false" />
        <primaryKey name="ACTIVITY_PK" id="ACTIVITY_PK">
          <primaryKeyColumn columnid="ACTIVITY.ID" sequence="0" />
        </primaryKey>
      </table>
      <table name="SOCIETY" id="SOCIETY">
        <column id="SOCIETY.ID" name="ID" datatype="NUMBER" ispartofprimarykey="true" ispartofforeignkey="false" />
        <column id="SOCIETY.NAME" name="NAME" datatype="VARCHAR2" ispartofprimarykey="false" ispartofforeignkey="false" />
        <column id="SOCIETY.STUDENT_COLLEGE_ID_PRESIDENT" name="STUDENT_COLLEGE_ID_PRESIDENT" datatype="NUMBER" ispartofprimarykey="false" ispartofforeignkey="true" />
        <column id="SOCIETY.STUDENT_ID_PRESIDENT" name="STUDENT_ID_PRESIDENT" datatype="NUMBER" ispartofprimarykey="false" ispartofforeignkey="true" />
        <column id="SOCIETY.STUDENT_COLLEGE_ID_SECRETARY" name="STUDENT_COLLEGE_ID_SECRETARY" datatype="NUMBER" ispartofprimarykey="false" ispartofforeignkey="true" />
        <column id="SOCIETY.STUDENT_ID_SECRETARY" name="STUDENT_ID_SECRETARY" datatype="NUMBER" ispartofprimarykey="false" ispartofforeignkey="true" />
        <primaryKey name="SOCIETY_PK" id="SOCIETY_PK">
          <primaryKeyColumn columnid="SOCIETY.ID" sequence="0" />
        </primaryKey>
        <foreignKeyFromList>
          <foreignKey name="SOCIETY_STUDENT_PRESIDENT_FK" id="SOCIETY_STUDENT_PRESIDENT_FK" fromtable="SOCIETY" totable="STUDENT" mandatory="false">
            <foreignKeyColumn columnid="SOCIETY.STUDENT_COLLEGE_ID_PRESIDENT" sequence="0" />
            <foreignKeyColumn columnid="SOCIETY.STUDENT_ID_PRESIDENT" sequence="1" />
          </foreignKey>
          <foreignKey name="SOCIETY_STUDENT_SECRETARY_FK" id="SOCIETY_STUDENT_SECRETARY_FK" fromtable="SOCIETY" totable="STUDENT" mandatory="false">
            <foreignKeyColumn columnid="SOCIETY.STUDENT_COLLEGE_ID_SECRETARY" sequence="0" />
            <foreignKeyColumn columnid="SOCIETY.STUDENT_ID_SECRETARY" sequence="1" />
          </foreignKey>
          <foreignKey name="SOCIETY_COLLEGE_PRESIDENT_FK" id="SOCIETY_COLLEGE_PRESIDENT_FK" fromtable="SOCIETY" totable="COLLEGE" mandatory="false">
            <foreignKeyColumn columnid="SOCIETY.STUDENT_COLLEGE_ID_PRESIDENT" sequence="0" />
          </foreignKey>
          <foreignKey name="SOCIETY_COLLEGE_SECRETARY_FK" id="SOCIETY_COLLEGE_SECRETARY_FK" fromtable="SOCIETY" totable="COLLEGE" mandatory="false">
            <foreignKeyColumn columnid="SOCIETY.STUDENT_COLLEGE_ID_SECRETARY" sequence="0" />
          </foreignKey>
        </foreignKeyFromList>
      </table>
      <table name="SOCIETY_MEMBERSHIP" id="SOCIETY_MEMBERSHIP">
        <column id="SOCIETY_MEMBERSHIP.SOCIETY_ID" name="SOCIETY_ID" datatype="NUMBER" ispartofprimarykey="true" ispartofforeignkey="true" />
        <column id="SOCIETY_MEMBERSHIP.STUDENT_COLLEGE_ID" name="STUDENT_COLLEGE_ID" datatype="NUMBER" ispartofprimarykey="false" ispartofforeignkey="true" />
        <column id="SOCIETY_MEMBERSHIP.STUDENT_ID" name="STUDENT_ID" datatype="NUMBER" ispartofprimarykey="true" ispartofforeignkey="true" />
        <primaryKey name="SOCIETY_MEMBERSHIP_PK" id="SOCIETY_MEMBERSHIP_PK">
          <primaryKeyColumn columnid="SOCIETY_MEMBERSHIP.SOCIETY_ID" sequence="0" />
          <primaryKeyColumn columnid="SOCIETY_MEMBERSHIP.STUDENT_ID" sequence="1" />
        </primaryKey>
        <foreignKeyFromList>
          <foreignKey name="SOCIETY_MEMBERSHIP_STUDENT_FK" id="SOCIETY_MEMBERSHIP_STUDENT_FK" fromtable="SOCIETY_MEMBERSHIP" totable="STUDENT" mandatory="true">
            <foreignKeyColumn columnid="SOCIETY_MEMBERSHIP.STUDENT_COLLEGE_ID" sequence="0" />
            <foreignKeyColumn columnid="SOCIETY_MEMBERSHIP.STUDENT_ID" sequence="1" />
          </foreignKey>
          <foreignKey name="SOCIETY_MEMBERSHIP_SOCIETY_FK" id="SOCIETY_MEMBERSHIP_SOCIETY_FK" fromtable="SOCIETY_MEMBERSHIP" totable="SOCIETY" mandatory="true">
            <foreignKeyColumn columnid="SOCIETY_MEMBERSHIP.SOCIETY_ID" sequence="0" />
          </foreignKey>
          <foreignKey name="SOCIETY_MEMBERSHIP_COLLEGE_FK" id="SOCIETY_MEMBERSHIP_COLLEGE_FK" fromtable="SOCIETY_MEMBERSHIP" totable="COLLEGE" mandatory="true">
            <foreignKeyColumn columnid="SOCIETY_MEMBERSHIP.STUDENT_COLLEGE_ID" sequence="0" />
          </foreignKey>
        </foreignKeyFromList>
      </table>
      <table name="SOCIETY_ACTIVITY" id="SOCIETY_ACTIVITY">
        <column id="SOCIETY_ACTIVITY.SOCIETY_ID" name="SOCIETY_ID" datatype="NUMBER" ispartofprimarykey="true" ispartofforeignkey="true" />
        <column id="SOCIETY_ACTIVITY.ACTIVITY_ID" name="ACTIVITY_ID" datatype="NUMBER" ispartofprimarykey="true" ispartofforeignkey="true" />
        <primaryKey name="SOCIETY_ACTIVITY_PK" id="SOCIETY_ACTIVITY_PK">
          <primaryKeyColumn columnid="SOCIETY_ACTIVITY.SOCIETY_ID" sequence="0" />
          <primaryKeyColumn columnid="SOCIETY_ACTIVITY.ACTIVITY_ID" sequence="1" />
        </primaryKey>
        <foreignKeyFromList>
          <foreignKey name="SOCIETY_ACTIVITY_ACTIVITY_FK" id="SOCIETY_ACTIVITY_ACTIVITY_FK" fromtable="SOCIETY_ACTIVITY" totable="ACTIVITY" mandatory="true">
            <foreignKeyColumn columnid="SOCIETY_ACTIVITY.ACTIVITY_ID" sequence="0" />
          </foreignKey>
          <foreignKey name="SOCIETY_ACTIVITY_SOCIETY_FK" id="SOCIETY_ACTIVITY_SOCIETY_FK" fromtable="SOCIETY_ACTIVITY" totable="SOCIETY" mandatory="true">
            <foreignKeyColumn columnid="SOCIETY_ACTIVITY.SOCIETY_ID" sequence="0" />
          </foreignKey>
        </foreignKeyFromList>
      </table>
      <table name="COLLEGE" id="COLLEGE">
        <column id="COLLEGE.ID" name="ID" datatype="NUMBER" ispartofprimarykey="true" ispartofforeignkey="false" />
        <column id="COLLEGE.NAME" name="NAME" datatype="VARCHAR2" ispartofprimarykey="false" ispartofforeignkey="false" />
        <primaryKey name="COLLEGE_PK" id="COLLEGE_PK">
          <primaryKeyColumn columnid="COLLEGE.ID" sequence="0" />
        </primaryKey>
      </table>
</tableList>
<foreignKeyList>
<foreignKey name="SOCIETY_STUDENT_PRESIDENT_FK" id="SOCIETY_STUDENT_PRESIDENT_FK" fromTable="SOCIETY" toTable="STUDENT" mandatory="false"/>
<foreignKey name="SOCIETY_STUDENT_SECRETARY_FK" id="SOCIETY_STUDENT_SECRETARY_FK" fromTable="SOCIETY" toTable="STUDENT" mandatory="false"/>
<foreignKey name="SOCIETY_MEMBERSHIP_STUDENT_FK" id="SOCIETY_MEMBERSHIP_STUDENT_FK" fromTable="SOCIETY_MEMBERSHIP" toTable="STUDENT" mandatory="true"/>
<foreignKey name="STUDENT_COLLEGE_FK" id="STUDENT_COLLEGE_FK" fromTable="STUDENT" toTable="COLLEGE" mandatory="true"/>
<foreignKey name="SOCIETY_ACTIVITY_ACTIVITY_FK" id="SOCIETY_ACTIVITY_ACTIVITY_FK" fromTable="SOCIETY_ACTIVITY" toTable="ACTIVITY" mandatory="true"/>
<foreignKey name="SOCIETY_ACTIVITY_SOCIETY_FK" id="SOCIETY_ACTIVITY_SOCIETY_FK" fromTable="SOCIETY_ACTIVITY" toTable="SOCIETY" mandatory="true"/>
<foreignKey name="SOCIETY_MEMBERSHIP_SOCIETY_FK" id="SOCIETY_MEMBERSHIP_SOCIETY_FK" fromTable="SOCIETY_MEMBERSHIP" toTable="SOCIETY" mandatory="true"/>
<foreignKey name="SOCIETY_COLLEGE_PRESIDENT_FK" id="SOCIETY_COLLEGE_PRESIDENT_FK" fromTable="SOCIETY" toTable="COLLEGE" mandatory="false"/>
<foreignKey name="SOCIETY_COLLEGE_SECRETARY_FK" id="SOCIETY_COLLEGE_SECRETARY_FK" fromTable="SOCIETY" toTable="COLLEGE" mandatory="false"/>
<foreignKey name="SOCIETY_MEMBERSHIP_COLLEGE_FK" id="SOCIETY_MEMBERSHIP_COLLEGE_FK" fromTable="SOCIETY_MEMBERSHIP" toTable="COLLEGE" mandatory="true"/>
</foreignKeyList>
</database>
</databaseDefinition>';


$oParser = new XmlParser();
$oFactory = new DatabaseFactory( new XmlDatasource( $oParser->Parse( $sXml ) ) );
$oDatabase = $oFactory->ConstructDatabase();

$oConfig = new HtmlRendererConfiguration();
echo( HtmlDatabaseRenderer::Render(  $oConfig, $oDatabase ) );


?>
</body>
</html>
